package com.yyj.service;

import com.yyj.dao.TPropertyRoomMapper;
import com.yyj.model.TPropertyRoom;
import com.yyj.model.TPropertyRoomExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class RoomService {

    @Autowired
    private TPropertyRoomMapper roomMapper;

    public List<TPropertyRoom> listRooms(){
        return roomMapper.selectByExample(null);
    }

    public void addRoom(String roomNum , BigDecimal square){
        TPropertyRoom tPropertyRoom = new TPropertyRoom();
        tPropertyRoom.setRoomNum(roomNum);
        tPropertyRoom.setSquare(square);
        roomMapper.insert(tPropertyRoom);
    }

    public TPropertyRoom queryRoomByNum(String roomNum){
        TPropertyRoomExample example = new TPropertyRoomExample();
        TPropertyRoomExample.Criteria criteria = example.createCriteria();
        criteria.andRoomNumEqualTo(roomNum);
        List<TPropertyRoom> list = roomMapper.selectByExample(example);
        if(list.size() > 0){
            return list.get(0);
        }
        return null;

    }

}
